<template>
  <view class="add-baby-modal" :class="addBabyClass" catchtouchmove="true">
    <view class="modal-main">
      <borderContainer
        v-for="item in otherBaby"
        :key="item.id"
        bg-color="#fffbea"
        bd-color="#cb9064"
        class="modal-main-item"
      >
        <view class="item-content">
          <image
            :lazy-load="true"
            class="item-content-avatar"
            :src="item.avatar"
          />
          <view class="item-content-main">
            <view class="name">{{ item.name }} </view>
            <view class="grade" v-if="item.city_name">
              <view class="grade-item">{{ item.city_name }}</view
              ><text />
              <view class="grade-name">{{ item.grade_name }}</view>
            </view>
          </view>
          <view class="item-content-button" @tap="handleToggleChild(item)">
            点击切换
          </view>
        </view>
      </borderContainer>
      <finishButton
        class="modal-main-button"
        :width="300"
        :background-bg="smallButtonBg"
        @click="handleToEditBabyInfo"
        v-if="!have_three_babys"
      >
        新增宝贝
      </finishButton>
    </view>
    <view class="mantle" @tap="handleClose" />
  </view>
</template>
<script>
import Taro from "@tarojs/taro";
import finishButton from "@/components/finish-button/index";
import borderContainer from "@/components/border-box/index";
import { smallButtonBg } from "@/libs/image-url";
export default {
  components: {
    finishButton,
    borderContainer
  },
  props: {
    /**是否显示弹窗 */
    isOpened: { type: Boolean, default: false },
    otherBaby: { type: Array, default: () => [] },
    have_three_babys: { type: Boolean, default: false }
  },
  data() {
    return {
      smallButtonBg
    };
  },
  computed: {
    addBabyClass() {
      return {
        "add-baby-opened": this.isOpened
      };
    }
  },
  methods: {
    handleToggleChild(data) {
      this.$emit("toggle-child", data);
    },
    handleClose() {
      this.$emit("update:isOpened", false);
    },
    handleToEditBabyInfo() {
      this.handleClose();
      Taro.navigateTo({
        url: `/package/mine/edit-baby/index`
      });
    }
  }
};
</script>

<style lang="scss">
@import "@/assets/scss/tools.scss";
.add-baby-modal {
  height: 0;
  position: absolute;
  width: 100%;
  top: 0;
  display: flex;
  flex-direction: column;
  z-index: -1;
  transition: all 0.2s;
  .modal-main {
    opacity: 0;
    transition: all 0.2s;
    background-color: #fff7e0;
    padding: 32px 30px 48px;
    &-item {
      height: 176px;
      margin-bottom: 32px;
      padding: 38px 32px 42px;
      &:last-child {
        margin-bottom: 48px;
      }
      .item-content {
        @include normal-flex;
        &-avatar {
          width: 96px;
          height: 96px;
          border: 2px solid #ffffff;
          border-radius: 50%;
          margin-right: 24px;
        }
        &-main {
          flex: 1;
          .name {
            width: 320px;
            @include textEllipsis;
            @include base-text(44px, 32px, #303133);
            margin-bottom: 12px;
          }
          .grade {
            @include normal-flex;
            @include base-text(44px, 24px, #ff8000, 400);
            line-height: 44px;
            padding: 0 16px;
            min-width: 164px;
            max-width: 198px;
            height: 42px;
            background: #fff8d2;
            border-radius: 100px;
            &-item {
              width: 72px;
              @include textEllipsis;
            }
            text {
              margin: 0 8px;
              height: 6px;
              width: 6px;
              border-radius: 50%;
              background-color: #ff8000;
            }
            &-name {
              width: 72px;
            }
          }
        }
        &-button {
          margin-left: 26px;
          width: 160px;
          border: 1px solid #ff8000;
          border-radius: 28px;
          box-sizing: border-box;
          @include base-text(56px, 28px, #ff8000, 400);
          line-height: 56px;
          text-align: center;
        }
        .active {
          border-color: #ffffff;
        }
      }
    }
    &-button {
      margin: 0 auto;
    }
  }
  .mantle {
    background: #000000;
    opacity: 0.5;
    flex: 1;
  }
}
.add-baby-opened {
  height: 100%;
  z-index: 999;
  .modal-main {
    opacity: 1;
  }
}
</style>
